package com.example.chapter3_1.service.iml;


import com.example.chapter3_1.entity.User;
import com.example.chapter3_1.mapper.UserDao;
import com.example.chapter3_1.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
public class UserServiceIml implements UserService {
    @Autowired
    private UserDao userDao;

    @Override
    public int register(User user) {
        if (userDao.findUserByName(user.getUsername())!=0){
            //用户名在数据库中存在，注册失败,抛出异常
            throw new RuntimeException("用户已存在");
        }
        //如果数据库中不存在这个用户名，就添加到数据库中去
        return userDao.creatUser(user);
    }
}
